unit MongoDB;

interface

uses
  MVCFramework, MVCFramework.Commons,MongoDB.Module;

type

  [MVCPath('/')]
  TMongoDB = class(TMVCController)
  private
    FMongoDBModule : TMongoDBModule;
  public
    [MVCPath('/MongoDB')]
    [MVCHTTPMethod([httpPOST])]
    procedure GetSpecializedHello(CXT:TWebContext);
  protected
    procedure OnBeforeAction(Context: TWebContext; const AActionName: string; var Handled: Boolean); override;
    procedure OnAfterAction(Context: TWebContext; const AActionName: string); override;
  end;

implementation

uses
  MVCFramework.Logger;


procedure TMongoDB.GetSpecializedHello(CXT:TWebContext);
begin
//  Render('Hello ' + FirstName);
  Render (FMongoDBModule.GetMongoDB);
end;

procedure TMongoDB.OnAfterAction(Context: TWebContext; const AActionName: string); 
begin
  { Executed after each action }
  inherited;
  FMongoDBModule.Free;
end;

procedure TMongoDB.OnBeforeAction(Context: TWebContext; const AActionName: string; var Handled: Boolean);
begin
  { Executed before each action
    if handled is true (or an exception is raised) the actual
    action will not be called }
  inherited;
   FMongoDBModule :=TMongoDBModule.create(nil);
end;


end.
